#include "PAP_defs.h"
#include "derivative.h"
#include "ADC_HAL_KA.h"
#include "GPIO_HAL_KA.h"

//#include "BUCK_Handler.h"

#define ADC_SOLAR_PANEL_CHAN    3   // Corresponding ADC channel and pin number

#define ADC_BATTERY_CHAN        6   // Corresponding ADC channel and pin number

#define ADC_MC34671_ISET  7   // Corresponding ADC channel and pin number

#define ISET_600MA  0x08
#define ISET_550MA  0x04
#define ISET_300MA  0x02
#define ISET_250MA  0x01

#define WAIT_FOR_BATTERY    0x01
#define WAIT_FOR_BUCK       0x02
#define TRICKLE_CHARGE      0x04
#define CONSTANT_CURRENT    0x08
#define CONSTANT_VOLTAGE    0x10
#define WAIT_FOR_SUN1       0x20
#define WAIT_FOR_SUN2       0x40
#define UNSPECIFIED_STATE   0x80

#define VOLTAGE_BAT_MIN     0x0183
#define VOLTAGE_BAT_MAX     0x027C

#define SOLAR_PANEL_VOLTAGE_MIN 0x01F9

#define MC34671_DISABLE     1
#define MC34671_ENABLE      0

#define ISET_1V_VALUE   294

void vfnMC34671_IncreaseISET (void);

void vfnMC34671_DecreaseISET (void);

uint8 u8MC34671_IsMaxISET (void);

uint8 u8MC34671_IsMinISET (void);

void vfnMC34671_StateInit (void);

void vfnMC34671_StorePanelVoltage (void);

uint8 u8MC34671_IsPanelVoltageOK (void);

void vfnMC34671_UpdateStateMachine (void);

uint8 u8MC34671_IsBatteryPresent (void);

uint8 u8MC34671_IsIbatConstant (void);

uint8 u8MC34671_IsIbatUnderEOC (void);